<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计算器练习</title>
</head>
<body>
<input type="text" id="i1">
<input type="text" id="i2">
<input type="button" value="加" onclick="fn(1)">
<input type="button" value="减" onclick="fn(2)">
<input type="button" value="乘" onclick="fn(3)">
<input type="button" value="除" onclick="fn(4)">
<hr>
<div id="result_div">结果:</div>

<script>

    function fn(x) {
        let i = document.getElementById("i1");
        let j = document.getElementById("i2");
        let d = document.getElementById("result_div");
        switch (x) {
            case 1://加
                d.innerText = "结果:"+(i.value*1+i.value*1);
                break;
            case 2://减
                d.innerText = "结果:"+(i.value*1-i.value*1);
                break;
            case 3://乘
                d.innerText = "结果:"+(i.value*i.value);
                break;
            case 4://除
                d.innerText = "结果:"+(i.value/i.value);
                break;

        }

    }


</script>

</body>
</html>